<template>
  <header class="header-nav">
    <!-- 左侧logo + 标题 -->
    <div class="logo-title">
      <img src="@/assets/logo.svg" alt="logo" class="logo">
      <span class="title">现代化系统</span>
    </div>
    <!-- 中间导航链接 -->
    <nav class="nav-links">
      <router-link to="/" class="link" exact>首页</router-link>
      <router-link to="/about" class="link">关于我们</router-link>
      <router-link to="/products" class="link">产品中心</router-link>
      <router-link to="/services" class="link">服务支持</router-link>
      <router-link to="/contact" class="link">联系我们</router-link>
    </nav>
    <!-- 右侧用户菜单 -->
    <div class="user-menu">
      <div class="user-dropdown">
        <button class="menu-btn">
          <span class="user-icon">👤</span>
          <span class="user-text">用户中心</span>
          <span class="dropdown-arrow">▼</span>
        </button>
        <div class="dropdown-content">
          <a href="#profile">个人资料</a>
          <a href="#settings">系统设置</a>
          <a href="#logout">退出登录</a>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup lang="ts">
// 用户菜单下拉交互
import { ref } from 'vue'

const isDropdownOpen = ref(false)

const toggleDropdown = () => {
  isDropdownOpen.value = !isDropdownOpen.value
}

// 点击其他地方关闭下拉菜单
import { onMounted, onUnmounted } from 'vue'

onMounted(() => {
  document.addEventListener('click', handleClickOutside)
})

onUnmounted(() => {
  document.removeEventListener('click', handleClickOutside)
})

const handleClickOutside = (event: Event) => {
  const dropdown = document.querySelector('.user-dropdown')
  if (dropdown && !dropdown.contains(event.target as Node)) {
    isDropdownOpen.value = false
  }
}
</script>

<style scoped>
.header-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30px;
  height: 70px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 45px;
  height: 45px;
  border-radius: 8px;
  transition: transform 0.3s ease;
}

.logo:hover {
  transform: scale(1.05) rotate(5deg);
}

.title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

.nav-links {
  display: flex;
  gap: 10px;
}

.link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 30px;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
}

.link:hover,
.link.router-link-active {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.link.router-link-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 3px;
  background-color: #fff;
  border-radius: 3px;
}

.user-menu {
  display: flex;
  align-items: center;
}

.user-dropdown {
  position: relative;
}

.menu-btn {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-btn:hover {
  background-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.user-icon {
  font-size: 18px;
}

.dropdown-arrow {
  font-size: 12px;
  transition: transform 0.3s ease;
}

.user-dropdown:hover .dropdown-arrow,
:deep(.dropdown-open) .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-content {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background-color: #fff;
  min-width: 180px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
  z-index: 1001;
}

.user-dropdown:hover .dropdown-content,
:deep(.dropdown-open) .dropdown-content {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-content a {
  color: #333;
  padding: 12px 20px;
  text-decoration: none;
  display: block;
  font-size: 14px;
  transition: all 0.2s ease;
}

.dropdown-content a:hover {
  background-color: #f5f5f5;
  color: #667eea;
}

.dropdown-content a:last-child {
  border-radius: 0 0 12px 12px;
  color: #e74c3c;
}

.dropdown-content a:first-child {
  border-radius: 12px 12px 0 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-nav {
    padding: 0 15px;
    height: 60px;
  }
  
  .nav-links {
    display: none;
  }
  
  .title {
    font-size: 18px;
  }
  
  .logo {
    width: 35px;
    height: 35px;
  }
  
  .menu-btn {
    padding: 8px 15px;
  }
  
  .user-text {
    display: none;
  }
}
</style>